package com.app.control;

import com.app.bean.User;
import com.google.gson.Gson;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by fanghui on 2017/10/3.
 */
@RestController
public class AppController {

    @ApiOperation("首页")
    @ApiImplicitParam()
    @RequestMapping(value = "index", method = RequestMethod.GET)
    public ModelAndView index(String redirect) {
        return new ModelAndView("index");
    }

    @ApiOperation(value = "删除用户", notes = "根据url的id来指定删除对象")
    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Long")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    @ResponseBody
    public Boolean delete(Long userId) {
        System.out.print(userId);
        return true;
    }

    @ApiOperation(value = "新增用户", notes = "根据提交用户对象新增用户,json格式传递数据", produces = "application/json")
    @ApiImplicitParam(name="user", value = "user对象", required = true, dataType = "User")
    @RequestMapping(value = "save", method = RequestMethod.POST)
    public User save(@RequestBody User user) {
        System.out.print(new Gson().toJson(user));
        return user;
    }

}
